Previous Book Contents Book Index Next

Inside Macintosh: Overview /
Chapter 9 - Processes


Specifying Processing Options

To take full advantage of the cooperative multitasking environment provided by the Macintosh system software, you need to inform the Operating System about the processing capabilities and requirements of your application. You need to indicate, for example, the partition size your application needs in order to execute most effectively. You also need to indicate whether your application can do any processing while it is in the background. If it cannot do any background processing, there's no use in having the Process Manager give your application access to the CPU while it's in the background.

You specify these and other processing options to the Operating System by including in your application's resource fork a resource of type 'SIZE', known as its size resource. The size resource contains several long integers and many flag bits, which together give the Process Manager the information it needs to launch your application and control its processing.

IMPORTANT
Every application executing in system software version 7.0 and later, as well as every application executing in system software version 6.0 with MultiFinder, should contain a size resource.
A 'SIZE' resource consists of a 16-bit flags field, followed by two 32-bit size fields. The flags field specifies operating characteristics of your application, and the size fields indicate the minimum and preferred partition sizes for your application. The minimum partition size is the actual limit below which your application will not run. The preferred partition size is the memory size at which your application can run most effectively. The Operating System attempts to secure this preferred amount of memory when your application is launched. If that amount of memory is unavailable, your application is placed into the largest contiguous block available, provided that it is larger than the specified minimum size.

Note
If the amount of available memory is between the minimum and the preferred sizes, the Finder displays a dialog box asking if the user wants to run the application using the amount of memory available. If your application does not have a 'SIZE' resource, it is assigned a default partition size of 512 KB, and the Process Manager uses a default value of FALSE for all specifications normally defined by constants in the flags field.
When you define a 'SIZE' resource, you should give it a resource ID of -1. A user can modify the preferred size in the Finder's information window for your application. If the user does alter the partition size, the Operating System creates a new 'SIZE' resource having a resource ID of 0 in your application's resource fork. At application launch time, the Process Manager looks for a 'SIZE' resource with ID 0; if this resource is not found, the Process Manager uses your original 'SIZE' resource (with ID -1). This new 'SIZE' resource is also created when the user modifies any of the other settings in the resource.

Listing 9-1 shows the Rez input for a sample 'SIZE' resource.

Listing 9-1 The Rez input for a sample 'SIZE' resource

resource 'SIZE' (-1) {
   reserved,                     /*reserved*/
   acceptSuspendResumeEvents,    /*accepts suspend and resume events*/
   reserved,                     /*reserved*/
   cannotBackground,             /*can't use background null events*/
   doesActivateOnFGSwitch,       /*activates own windows in */
                                 /* response to OS events*/
   backgroundAndForeground,      /*application has a user interface*/
   dontGetFrontClicks,           /*don't return mouse events */
                                 /* in front window on resume*/
   ignoreAppDiedEvents,          /*doesn't want app-died events*/
   is32BitCompatible,            /*works with 24- or 32-bit addr*/
   notHighLevelEventAware,       /*can't use high-level events*/
   onlyLocalHLEvents,            /*can't use remote high-level events*/
   notStationeryAware,           /*can't use stationery documents*/
   dontUseTextEditServices,      /*can't use inline input services*/
   reserved,                     /*reserved*/
   reserved,                     /*reserved*/
   reserved,                     /*reserved*/
   kPrefSize * 1024,             /*preferred memory size*/
   kMinSize * 1024               /*minimum memory size*/
};
The 'SIZE' resource specification in Listing 9-1 indicates, among other things, that the application accepts suspend and resume events, does no processing in the background, activates or deactivates any windows as necessary in response to operating-system events, has a user interface, and doesn't want to receive any mouse event associated with a resume event that was caused by the user clicking in the application's front window. In this example, the Rez input file must define values for the constants kPrefSize and kMinSize; for example, if kPrefSize is set to 50, the preferred partition size is 50 KB.

Note
See the chapter "Event Manager" in Inside Macintosh: Macintosh Toolbox Essentials for a more complete description of the 'SIZE' resource.
The numbers you specify as your application's preferred and minimum partition sizes depend on the particular memory requirements of your application. Your application's memory requirements depend in turn on the size of your application's A5 world, heap, and stack. (See the chapter "Memory" earlier in this book for details about these areas of your application's partition.)

You can usually make a fairly reliable estimate of the size of your application's A5 world by determining the size of your application's global variables and its jump table (whose size you can determine by looking at the size of your compiled application's 'CODE' resource with ID 0). You can also make a good guess about the size of your application's static heap objects--objects that are always present during the execution of your application (for example, code segments, Toolbox data structures for window records, and so on).

It's a little bit more work to determine the amount of space you'll need to reserve for dynamic heap objects. These include objects created on a per-document basis (which may vary in size proportionally with the document itself) and objects required for specific commands or functions. Perhaps the best advice to follow in determining your application's minimum and preferred partition sizes is to experiment with reasonable values and make sure that there is always enough memory to meet reasonable requests from the user. You can also use tools such as MacsBug's heap-exploring commands to help empirically determine your application's dynamic memory requirements.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
9 JUL 1996